using HCore.IOC.Beans.Factory.Attribute.Attr;
using HCore.IOC.Context.Event.Attr;
using HCore.Tests.Runtime.ShootingEditor2D.Scripts.Support.CommandQuery;
using HCore.Tests.Runtime.ShootingEditor2D.Scripts.System.GunSystem;
using HCore.Tests.Runtime.ShootingEditor2D.Scripts.System.StatSystem;
using UnityEngine;

namespace HCore.Tests.Runtime.ShootingEditor2D.Scripts.Command
{
    /// <summary>
    ///     击杀敌人
    /// </summary>
    public class KilledEnemyCommand : ICommand
    {
    }

    [IOC.Context.Stereotype.Component]
    public class KilledEnemyCommandHandler
    {
        [Autowired] private IGunSystem mGunSystem;
        [Autowired] private IStatSystem mStatSystem;

        [EventListener]
        private void ExecuteCommand(KilledEnemyCommand command)
        {
            // 更新统计数据
            mStatSystem.KillCount.Value++;

            // 补充弹药: 打一个敌人20%不给弹药，80%给1~3发弹药
            var randomValue = Random.Range(0, 100);
            if (randomValue < 80) mGunSystem.CurrentGun.BulletCountInGun.Value += Random.Range(1, 4);
        }
    }
}